package tom.spring.cloud.integration.receiver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import tom.spring.cloud.msg.MyInput;
import tom.spring.cloud.msg.vo.Alien;
import tom.spring.cloud.msg.vo.Dog;
import tom.spring.cloud.msg.vo.User;

import java.util.Date;

/**
 * 使用自定义Channel，接收topic0的消息，配置在application.yml中。
 * ServiceActivator默认使用SimpleTypeConvert转换消息参数
 * Transformer可以自定义消息转换
 * @author ZHUFEIFEI
 */
@Slf4j
@EnableBinding({MyInput.class})
public class Receiver02 {

    @ServiceActivator(inputChannel = MyInput.INPUT)
    public void receive02str(String payload) {
        log.info("receive02 string: {}", payload);
    }

    @ServiceActivator(inputChannel = MyInput.INPUT)
    public void receive02Date(Date date) {
        log.info("receive02 date: {}", date);
    }

    @ServiceActivator(inputChannel = MyInput.INPUT)
    public void receive02Dog(Dog dog) {
        log.info("receive02 dog: {}", dog);
    }


    @ServiceActivator(inputChannel = MyInput.INPUT)
    public void receive02User(User user) {
        log.info("receive02 user: {}", user);
    }

    @ServiceActivator(inputChannel = MyInput.INPUT)
    public void receive02Alien(@Header(name = "region") String region, @Payload Alien alien) {
        log.info("receive02 alien: {} with region: {}", alien, region);
    }

}
